6.5 Expand the VeryLongInt class by testing and defining methods that have the following method specifications:
a. /**
* Initializes this VeryLongInt object from a given int.
*
* @param n - the int from which this VeryLongInt is initialized.
*
* @throws IllegalArgumentException - if n is negative.
*
*/
public VeryLongInt (int n)
b. /**
* Returns the number of digits in this VeryLongInt object.
*
* @return the number of digits in this VeryLongInt object.
*
*/
public int size()
c. /**
* Returns true if this VeryLongInt object is less than another VeryLongInt
* object. The worstTime(n) is O(n).
*
* @param otherVeryLong - the other VeryLongInt object.
*
* @return true - if this VeryLongInt is less than otherVeryLong.
*
* @throws NullPointerException - if otherVeryLong is null
*
*/
public boolean less (VeryLongInt otherVeryLong)
d. /**
* Returns true if this VeryLongInt object is greater than another VeryLongInt
* object. The worstTime(n) is O(n).
*
* @param otherVeryLong - the other VeryLongInt object.
*
* @return true - if this VeryLongInt is greater than otherVeryLong.
*
* @throws NullPointerException - if otherVeryLong is null
*
*/
public boolean greater (VeryLongInt otherVeryLong)
e. /**
* Returns true if this VeryLongInt object is equal to a specified object.
* The worstTime(n) is O(n).
*
* @param obj - the specified object that this VeryLongInt is compared to.
*
* @return true - if this VeryLongInt is equal to obj.
*
*/
public boolean equals (Object obj)
f. /**
* Stores a Fibonacci number in this VeryLongInt object.
*
* @param n - the index in the Fibonacci sequence
*
* @throws IllegalArgumentException - if n is not positive
*/
public void fibonacci (int n)
Example Suppose the following message is sent
tempInt.fibonacci (100);
Then tempInt's value will be 354224848179261915075-the 100th Fibonacci number.
Hint: Mimic the iterative design of the Fibonacci function from Lab 7. Both i and n will be ordinary int variables, but previous, current and temp will be VeryLongInt objects. After the loop, instead of
returning current, the calling object is modified by assigning to digits a copy of current.digits.
 
 
View Solution
 
 
 
<< Back Next >>